package com.zygh.policeasset.controller;

import cn.hutool.core.util.StrUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.Department;
import com.zygh.policeasset.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/department"})
@Api(tags = {"部门管理"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/DepartmentController.class */
public class DepartmentController {
    @Autowired
    DepartmentService departmentService;

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public Object getExcel(@RequestBody Department department) throws Exception {
        if (StrUtil.isEmpty(department.getDepartmentName())) {
            return new CommonResult().validateFailed("部门名称不能为空");
        }
        if (StrUtil.isEmpty(department.getDepartmentNum())) {
            return new CommonResult().validateFailed("部门编号不能为空");
        }
        if (this.departmentService.findDepartment(null, department.getDepartmentNum(), null).size() > 0) {
            return new CommonResult().validateFailed("部门编号重复");
        }
        if (this.departmentService.findDepartment(null, null, department.getDepartmentName()).size() > 0) {
            return new CommonResult().validateFailed("部门名称重复");
        }
        if (this.departmentService.add(department).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改")
    public Object update(@RequestBody Department department) throws Exception {
        if (StrUtil.isEmpty(department.getDepartmentName())) {
            return new CommonResult().validateFailed("部门名称不能为空");
        }
        if (StrUtil.isEmpty(department.getDepartmentNum())) {
            return new CommonResult().validateFailed("部门编号不能为空");
        }
        if (this.departmentService.update(department).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/delete"}, method = {RequestMethod.POST})
    @ApiOperation("删除")
    public Object delete(@RequestBody Department department) throws Exception {
        if (StrUtil.isEmpty(department.getId().toString())) {
            return new CommonResult().validateFailed("主键不能为空");
        }
        if (this.departmentService.delete(department.getId()).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/findDepartment"}, method = {RequestMethod.GET})
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键编号", required = false, paramType = "query"), @ApiImplicitParam(name = "departmentNum", value = "部门编号", required = false, paramType = "query"), @ApiImplicitParam(name = "departmentName", value = "部门名称", required = false, paramType = "query")})
    @ApiOperation("查询所有")
    public Object findDepartment(Integer id, String departmentNum, String departmentName) throws Exception {
        return this.departmentService.findDepartment(id, departmentNum, departmentName);
    }

    @RequestMapping(value = {"/findAllDepartment"}, method = {RequestMethod.GET})
    @ApiOperation("查询所有")
    public Object findAllDepartment(){
        return this.departmentService.findDepartment(null, null, null);
    }
}